/**
 * Copyright ©2016-2022 tianyu education Corporation, All Rights Reserved
 * http://www.whty.com.cn/
 */
package profile.hujia.shiro.study.service.utils;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.stereotype.Service;
import profile.hujia.shiro.study.service.constant.EncryptionConstant;

/**
 * class info
 *
 * @author hujia
 * @date 2019-12-10 09:58
 */
@Service
public class EncryptionService {

    private SecureRandomNumberGenerator secureRandomNumberGenerator;

    public EncryptionService() {
        secureRandomNumberGenerator = new SecureRandomNumberGenerator();
    }

    public String getSalt() {
        return secureRandomNumberGenerator.nextBytes().toHex();
    }

    public String encryption(String salt, String password) {

        return new SimpleHash(EncryptionConstant.ALGORITHM_NAME, password,
                ByteSource.Util.bytes(salt), EncryptionConstant.HASH_ITERATIONS).toHex();
    }
}